package com.example.server.http;

import com.example.server.ServerImpl;
import com.example.transport.message.Request;
import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.Protocol;
import org.smartboot.socket.transport.AioQuickServer;
import org.smartboot.socket.transport.AioSession;

import java.nio.ByteBuffer;

public class DefaultHttpServer extends ServerImpl {

    private AioQuickServer server;

    public DefaultHttpServer(int port) {
        super(port);
    }

    @Override
    public void init() throws Exception {
        this.server = new AioQuickServer(getPort(), new Protocol<Request>() {
            @Override
            public Request decode(ByteBuffer readBuffer, AioSession session) {
                return null;
            }
        }, new MessageProcessor<Request>() {
            @Override
            public void process(AioSession session, Request request) {

            }
        });
    }

    @Override
    public void start() throws Exception {
        this.server.start();
    }

    @Override
    public void stop() throws Exception {
        this.server.shutdown();
    }
}
